import java.util.ArrayList;
import java.util.List;
/**
 * Created by IntelliJ IDEA.
 * User: chen
 * Date: 2024/1/14
 */
public class TreeToList {


    /**
     * 把树 转成list
     * @param lists
     * @return
     */
    private List<BibookInvestmentPlanEntity> getTreeChangeList(List<BibookInvestmentPlanEntity> lists){

        List<BibookInvestmentPlanEntity> list = new ArrayList<>();

        lists.forEach(o->{
            this.treeToList(o,list);
        });

        return list;
    }


    /**
     * 将tree结构数据转成List结构
     * @param list
     * @return
     */
    public void treeToList(BibookInvestmentPlanEntity node,List<BibookInvestmentPlanEntity> list){
        if(list==null){
            list=new ArrayList<BibookInvestmentPlanEntity>();
        }
        //设置当前节点的必要数据
        BibookInvestmentPlanEntity bibookInvestmentPlanEntity = new BibookInvestmentPlanEntity();
        bibookInvestmentPlanEntity.setId(bibookInvestmentPlanEntity.getId());
        bibookInvestmentPlanEntity.setInvestmentPlanId(bibookInvestmentPlanEntity.getInvestmentPlanId());
        bibookInvestmentPlanEntity.setCourseNumber(bibookInvestmentPlanEntity.getCourseNumber());
        bibookInvestmentPlanEntity.setCourseLevel(bibookInvestmentPlanEntity.getCourseName());
        bibookInvestmentPlanEntity.setCourseName(bibookInvestmentPlanEntity.getCourseName());
        bibookInvestmentPlanEntity.setPid(bibookInvestmentPlanEntity.getPid());
        bibookInvestmentPlanEntity.setNormTotal(bibookInvestmentPlanEntity.getNormTotal());
        bibookInvestmentPlanEntity.setNormUnilateral(bibookInvestmentPlanEntity.getNormUnilateral());
        bibookInvestmentPlanEntity.setAdjustTotal(bibookInvestmentPlanEntity.getAdjustTotal());
        bibookInvestmentPlanEntity.setAdjustUnilateral(bibookInvestmentPlanEntity.getAdjustUnilateral());
        bibookInvestmentPlanEntity.setManual(bibookInvestmentPlanEntity.getManual());
        bibookInvestmentPlanEntity.setInvestType(bibookInvestmentPlanEntity.getInvestType());
        bibookInvestmentPlanEntity.setInvestTypeName(bibookInvestmentPlanEntity.getInvestTypeName());
        bibookInvestmentPlanEntity.setCreatTime(bibookInvestmentPlanEntity.getCreatTime());
        bibookInvestmentPlanEntity.setSubmitSave(bibookInvestmentPlanEntity.getSubmitSave());
        bibookInvestmentPlanEntity.setCoding(bibookInvestmentPlanEntity.getCoding());
        bibookInvestmentPlanEntity.setDataSource(bibookInvestmentPlanEntity.getDataSource());
        bibookInvestmentPlanEntity.setVersionId(bibookInvestmentPlanEntity.getVersionId());
        bibookInvestmentPlanEntity.setColum1(bibookInvestmentPlanEntity.getColum1());
        bibookInvestmentPlanEntity.setColum2(bibookInvestmentPlanEntity.getColum2());
        bibookInvestmentPlanEntity.setChildren(new ArrayList<BibookInvestmentPlanEntity>());
        list.add(bibookInvestmentPlanEntity);
        //遍历递归子节点
        if(ifChilds(node.getChildren())){
            for (int i = 0; i < node.getChildren().size(); i++) {
                BibookInvestmentPlanEntity node_= node.getChildren().get(i);
                treeToList(node_,list);
            }
        }
    }




    //判断是否存在子集
    private static boolean ifChilds(List<?> list) {
        boolean flag = false;
        if (list != null && list.size() != 0) {
            flag = true;
        }

        return flag;
    }


}
